﻿
Partial Public Class Efrm_Historial_Tareas
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ViewState("fk_task") = "1"
            carga_grilla()
        End If
    End Sub

    Sub carga_grilla()
        Dim exec As New DotNetDAL.SQLPersistence(False, "cnn", DotNetDAL.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence

        rp.StoredProcedure = "SP_TASK_CONSULTA_ESTADO"
        rp.AddParametro(ViewState("fk_task"))
        exec.ExecuteDatatable(rp)

        If rp.TieneDatos Then
            grdEstado.DataSource = rp.DtTable
            grdEstado.DataBind()
            grdEstado.UpdateAfterCallBack = True

            For i = 0 To grdEstado.Items.Count - 1

                If i = 0 Then
                    grdEstado.Items(0).Cells(0).FindControl("LinkEliminar").Visible = True
                    grdEstado.Items(0).Cells(0).FindControl("LinkVerLog").Visible = True
                End If

                grdEstado.Items(i).Cells(2).Text = grdEstado.Items(i).Cells(2).Text.Substring(6, 2) & "-" & grdEstado.Items(i).Cells(2).Text.Substring(4, 2) & "-" & grdEstado.Items(i).Cells(2).Text.Substring(0, 4)
                grdEstado.Items(i).Cells(3).Text = grdEstado.Items(i).Cells(3).Text.Substring(0, 2) & ":" & grdEstado.Items(i).Cells(3).Text.Substring(2, 2)
                grdEstado.Items(i).Cells(4).Text = grdEstado.Items(i).Cells(4).Text.Substring(6, 2) & "-" & grdEstado.Items(i).Cells(4).Text.Substring(4, 2) & "-" & grdEstado.Items(i).Cells(4).Text.Substring(0, 4)
                grdEstado.Items(i).Cells(5).Text = grdEstado.Items(i).Cells(5).Text.Substring(0, 2) & ":" & grdEstado.Items(i).Cells(5).Text.Substring(2, 2)
            Next
            ConfirmacionEstado()
        End If

    End Sub

    Protected Sub LinkVerLog_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim exec As New DotNetDAL.SQLPersistence(False, "cnn", DotNetDAL.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence
        Dim fila As DataGridItem
        fila = DirectCast(DirectCast(sender.parent.parent, System.Object), System.Web.UI.WebControls.DataGridItem)
        rp.StoredProcedure = "SP_TASK_LINK_LOG"
        rp.AddParametro(ViewState("fk_task"))
        rp.AddParametro(DirectCast(fila.Cells(7), System.Web.UI.WebControls.TableCell).Text)
        exec.ExecuteDatatable(rp)
        If rp.TieneDatos Then
            txt_MensajeError.Visible = True
            txt_MensajeError.UpdateAfterCallBack = True
            txt_MensajeError.Text = rp.DtTable.Rows(0).Item(2).ToString
            txt_MensajeError.UpdateAfterCallBack = True
        End If
    End Sub

    Sub ConfirmacionEstado()
        Dim i As Integer
        For i = 0 To grdEstado.Items.Count - 1
            DirectCast(grdEstado.Items(i).Cells(0).FindControl("LinkEliminar"), Anthem.LinkButton).Attributes.Add("onclick", "return confirm('" & ("¿Esta seguro de Re Procesar la Tarea") & "?')")
        Next
    End Sub

    Protected Sub LinkEliminar_Click1(ByVal sender As Object, ByVal e As EventArgs)
        Dim exec As New DotNetDAL.SQLPersistence(True, "cnn", DotNetDAL.SQLPersistence.Provider.SQLCLIENT)
        Dim rp As New DotNetResponse.SQLPersistence
        Dim fila As DataGridItem
        fila = DirectCast(DirectCast(sender.parent.parent, System.Object), System.Web.UI.WebControls.DataGridItem)
        'rp.StoredProcedure = "SP_TASK_DELETE_TAREA"
        'rp.AddParametro(DirectCast(fila.Cells(7), System.Web.UI.WebControls.TableCell).Text)
        'exec.ExecuteNonQuery(rp)
        'exec.Commit()

        'If rp.Errores Then
        'Else
        Dim fk_task As Integer = DirectCast(fila.Cells(11), System.Web.UI.WebControls.TableCell).Text
        Dim dll As String = Trim(DirectCast(fila.Cells(8), System.Web.UI.WebControls.TableCell).Text)
        Dim clase As String = Trim(DirectCast(fila.Cells(9), System.Web.UI.WebControls.TableCell).Text)
        Dim metodo As String = Trim(DirectCast(fila.Cells(10), System.Web.UI.WebControls.TableCell).Text)
        'carga_grilla()
        'End If

        'Dim task As New NegTask.Cls_Task
        'task.InvokeTask(fk_task, dll, clase, metodo)


        'If task.InvokeTask(fk_task, dll, clase, metodo) > 0 Then
        '    Cls_Mensaje.MsgError(img_mensaje, lbl_mensaje, Panel1, "Tarea en Proceso de Ejecución")
        'Else

        'End If




    End Sub

End Class